#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int INF=0x3f3f3f3f;
const int N=1510;
char b[N][N];
int st[N][N];
int st1[2*N][2*N];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int f;
int n,m;
string s;
void dfs(int x,int y)
{
	if(x>2*n)
	{
		dfs(1,y);
		return;
	}
	else if(x<=0)  
	{
		dfs(2*n,y);
		return;
	}
	if(y>2*m)
	{
		dfs(x,1);
		return;
	}
	else if(y<=0)
	{
		dfs(x,2*m);
		return;
	}
	if(f)
	{
		return;
	}
	int xx=(x-1)%n+1;
	int yy=(y-1)%m+1;
	if(b[xx][yy]=='#') return;
	if(st1[x][y]==1) return;
	st1[x][y]=1;
	if(st[xx][yy]==1)
	{
		f=1;
		return ;
	}
	st[xx][yy]=1;
	dfs(x-1,y);
	dfs(x+1,y);
	dfs(x,y-1);
	dfs(x,y+1);
	 
	return;
 }
int main()
{
	int x,y;
	while(cin>>n>>m)
	{
		f=0;
		for(int i=1;i<=n;i++)
		{
			cin>>s;
			for(int j=1;j<=m;j++)
			{
				b[i][j]=s[j-1];
				if(b[i][j]=='S')
				{
					x=i;
					y=j;
				}
			}
		}
		dfs(x,y);
		//cout<<st[1][3]<<' '<<st1[6][3];
		if(f) cout<<"Yes";
		else cout<<"No";
		cout<<endl;
		memset(st1,0,sizeof(st1));
		memset(st,0,sizeof(st1));
	}
	

	return 0;
}

